// Geometric Tools, Inc.
// http://www.geometrictools.com
// Copyright (c) 1998-2006.  All Rights Reserved
//
// The Wild Magic Library (WM3) source code is supplied under the terms of
// the license agreement
//     http://www.geometrictools.com/License/WildMagic3License.pdf
// and may not be copied or disclosed except in accordance with the terms
// of that agreement.

#include "Wm3FoundationPCH.h"
#include "Wm3TriMesh.h"
#include "Wm3IntrRay3Triangle3.h"
#include "Wm3CachedVector3fArray.h"
using namespace Wm3;

WM3_IMPLEMENT_RTTI(Wm3,TriMesh,Triangles);
WM3_IMPLEMENT_STREAM(TriMesh);
WM3_IMPLEMENT_DEFAULT_STREAM(TriMesh,Triangles);
WM3_IMPLEMENT_DEFAULT_NAME_ID(TriMesh,Triangles);

//----------------------------------------------------------------------------
TriMesh::TriMesh ()
{
    GeometryType = GT_TRIMESH;
}
//----------------------------------------------------------------------------
TriMesh::TriMesh (Vector3fArray* pkVertices, IntArray* pkIndices,
    bool bGenerateNormals, bool bCachedNormals)
    :
    Triangles(pkVertices,pkIndices,bGenerateNormals,bCachedNormals)
{
    GeometryType = GT_TRIMESH;
    if (bGenerateNormals)
    {
        GenerateNormals(bCachedNormals);
    }
}
//----------------------------------------------------------------------------
TriMesh::~TriMesh ()
{
}
//----------------------------------------------------------------------------
bool TriMesh::GetTriangle (int i, int& riV0, int& riV1, int& riV2) const
{
    if (0 <= i && i < GetTriangleQuantity())
    {
        const int* piIndex = &Indices->GetData()[3*i];
        riV0 = *piIndex++;
        riV1 = *piIndex++;
        riV2 = *piIndex;
        return true;
    }
    return false;
}
//----------------------------------------------------------------------------
